package servlet;

import model.classes;
import model.teacher;
import model.users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(value = "/addStuInfo")
public class addStuInfo extends HttpServlet{
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");

        String uaccount=req.getParameter("uaccount");

        String uname=req.getParameter("uname");

        String upassword=req.getParameter("upassword");

        int uage=0;

        if(req.getParameter("uage")!="" && req.getParameter("uage")!=null){
            uage=Integer.parseInt(req.getParameter("uage"));
        }

        String usex=req.getParameter("usex");

        String ucate=req.getParameter("ucate");
        System.out.println("----->"+ucate);

        if(uage!=0 && uaccount!=null&& uname!=null && upassword!=null && usex!=null && ucate!=null){
            if (users.addUserInfo(uaccount, uname, upassword, uage, usex, ucate)){
                req.setAttribute("addStuInfo","添加成功");
                req.getRequestDispatcher("/jsp/a_addStuInfo.jsp").forward(req,resp);
            }else{
                req.setAttribute("addStuInfo","添加失败");
                req.getRequestDispatcher("/jsp/a_addStuInfo.jsp").forward(req,resp);
            }
        }
        else{
            req.setAttribute("addStuInfo","请填写完整信息");
            req.getRequestDispatcher("/jsp/a_addStuInfo.jsp").forward(req,resp);
        }
    }
}
